package com.sky.controller.admin;


import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.IOrdersService;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author fcy
 * @since 2025-09-14
 */
@RestController("adminOrdersController")
@RequestMapping("/admin/order")
@Api(tags = "管理端订单接口")
public class OrdersController {
    @Autowired
    private IOrdersService ordersService;
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result<String> cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        ordersService.cancelAdmin(ordersCancelDTO);
        return Result.success();

    }
    /**
     * 各个状态的订单数量统计
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderOverViewVO> statistics() {
        OrderOverViewVO orderOverViewVO = ordersService.statistics();
        return Result.success(orderOverViewVO);
    }
    /**
     * 订单完成
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result<String> complete(@PathVariable Long id) {
        ordersService.complete(id);
        return Result.success();
    }
    /**
     * 拒单
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        ordersService.rejection(ordersRejectionDTO);
        return Result.success();
    }
    /**
     * 接单
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result<String> confirm( Long id) {
        ordersService.confirm(id);
        return Result.success();
    }
    /**
     * 查询订单详情
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderById(@PathVariable Long id) {
        return ordersService.getOrderById(id);
    }
    /**
     * 派送订单
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result<String> delivery(@PathVariable Long id) {
        ordersService.delivery(id);
        return Result.success();
    }

    @ApiOperation("订单搜索")
    @GetMapping("conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = ordersService.searchList(ordersPageQueryDTO);
        return Result.success(pageResult);
    }
}
